﻿using System;
using System.ComponentModel;
using RaytracerLib.MathLib;

namespace Raytracer.PropertyGridDecorators
{
    public class Vector3Properties
    {
        public readonly Action<Vector3> Setter;
        public readonly Func<Vector3> Getter;

        public Vector3Properties(Func<Vector3> a_getter, Action<Vector3> a_setter)
        {
            Getter = a_getter;
            Setter = a_setter;
        }

        public Vector3 ToVector3()
        {
            return new Vector3(X, Y, Z);
        }

        [TypeConverter(typeof(DoubleConverter))]
        public double X
        {
            get
            {
                return Getter().X;
            }
            set
            {
                Setter(new Vector3(value, Y, Z));
            }
        }

        [TypeConverter(typeof(DoubleConverter))]
        public double Y
        {
            get
            {
                return Getter().Y;
            }
            set
            {
                Setter(new Vector3(X, value, Z));
            }
        }

        [TypeConverter(typeof(DoubleConverter))]
        public double Z
        {
            get
            {
                return Getter().Z;
            }
            set
            {
                Setter(new Vector3(X, Y, value));
            }
        }
    }

    public class Vector3ReadonlyProperties
    {
        private Vector3 m_vector;

        public Vector3ReadonlyProperties(Vector3 a_vector)
        {
            m_vector = a_vector;
        }

        [TypeConverter(typeof(DoubleConverter))]
        public double X
        {
            get
            {
                return m_vector.X;
            }
        }

        [TypeConverter(typeof(DoubleConverter))]
        public double Y
        {
            get
            {
                return m_vector.Y;
            }
        }

        [TypeConverter(typeof(DoubleConverter))]
        public double Z
        {
            get
            {
                return m_vector.Z;
            }
        }
    }
}